package gui.cen.disp;

import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import javax.swing.BorderFactory;
import javax.swing.JPanel;

/*Author: John Archer, Contact: john.archer.jpa@gmail.com*/
public class Message extends JPanel{

    public Message(){
        super(new FlowLayout());
        this.setBorder(BorderFactory.createEmptyBorder(3,3,3,3));
    }

    private String msg = "";
    public void tickMSG(String m){msg = m;this.repaint();}


    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.setColor(Color.black);
        drawMessage(g);
    }

    private Graphics2D bufferGraphics = null;
    private Image offScreen = null;

    //use card layout and panels here to do movie!!
    private void drawMessage(Graphics g){
        final int imageHeight = 16;
        final int imageWidth = this.getWidth();
        this.setLayout(new FlowLayout(){public Dimension preferredLayoutSize(Container cont) {return (new Dimension(imageWidth, imageHeight));}});
        offScreen = this.createImage(imageWidth, imageHeight);
        bufferGraphics = (Graphics2D)offScreen.getGraphics();
        bufferGraphics.setColor(new Color(102, 102, 102));
        bufferGraphics.setFont(new Font("Tahoma", Font.BOLD, 12));
        bufferGraphics.drawString(msg, 5, 12);
        g.drawImage(offScreen, 0, 0, imageWidth, imageHeight, this);
    }
}
